package com.example.dummybriefejb;

import java.util.Date;

import javax.ejb.*;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.example.dummbriefgen.DummyBrief;
import com.example.dummbriefgen.DummyBriefGenerator;
import com.example.dummybriefejb.DummyBriefSpender;

public @Stateless class DummyBriefSpenderBean implements DummyBriefSpender {
	@PersistenceContext
	EntityManager em;
	@EJB
	private DummyBriefGenerator dummyBriefGen;
	
	public DummyBrief erzeugeDummyBrief(int absaetze){
		return dummyBriefGen.machMirEinenBrief(absaetze);
	}
	
	public void saveNewDummyBrief(String absender, String adressat, Date datum,String text){
		DummyBrief db = new DummyBrief();
		db.setAbsender(absender); db.setAdressat(adressat);
		db.setDatum(datum); db.setText(text);
	}
	public void loescheDummyBrief(DummyBrief db){
		em.remove(em.merge(db));
	}
	
}
